package org.jleaf.springcloud.webui.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yaoshuhong on 2016/8/3.
 */
@FeignClient(value = "USERSERVICE", fallback = UserService.UserServiceFallback.class)
public interface UserService {

    /**
     * 获取指定用户的基本信息
     *
     * @param id
     * @param status
     * @return
     */
    @RequestMapping("basicInfo")
    Map basicInfo(@RequestParam("id") Long id, @RequestParam("status") String status);

    @Component
    static class UserServiceFallback implements UserService {

        private static Logger log = LoggerFactory.getLogger(UserServiceFallback.class);

        @Override
        public Map basicInfo(@RequestParam("id") Long id, @RequestParam("status") String status) {
            log.info("feign内部自动hystrix");
            Map map = new HashMap<>();
            map.put("a", "asd");
            return map;
        }
    }
}
